import { Module } from '@nestjs/common';
import { BannerService } from './banner.service';
import { BannerController } from './banner.controller';
import { TypeOrmModule } from '@nestjs/typeorm';
import { Banner } from './entities/banner.entity';
import { MulterModule } from '@nestjs/platform-express';
import { diskStorage } from 'multer';
import { extname, join } from 'path';

@Module({
  imports: [
    TypeOrmModule.forFeature([Banner]),
    MulterModule.register({
      storage: diskStorage({
        destination: join(__dirname, '../upload/images'),
        filename: (_, file, callback) => { //req,file,callback
          const fileName = `${new Date().getTime() + extname(file.originalname)}`//文件名过滤
          return callback(null, fileName)
        }
      })
    })
  ],
  controllers: [BannerController],
  providers: [BannerService]
})
export class BannerModule { }
